package com.tc.vms.consumer;

import com.tc.vms.metric.VmsMetricsGroup;
import com.yammer.metrics.core.Meter;
import com.yammer.metrics.core.Timer;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * Created by yonghua.zhang on 2016/2/1.
 */
public class VmsConsumerMetrics extends VmsMetricsGroup {
    private final String metricsId;
    private final Meter consumeSuccessRate;
    private final Meter consumeFailureRate;
    private final Meter reconsumeSuccessRate;
    private final Meter reconsumeFailureRate;
    private final Timer totalCostOfMessage;
    private final Timer userCostOfMessage;

    public VmsConsumerMetrics(String metricsId) {
        this.metricsId = metricsId;
        Map<String, String> tags = new HashMap<String, String>(1);
        tags.put("client.id", metricsId);
        this.consumeSuccessRate = newMeter("ConsumeSuccessPerSec", "message", TimeUnit.SECONDS, tags);
        this.consumeFailureRate = newMeter("ConsumeFailurePerSec", "message", TimeUnit.SECONDS, tags);
        this.reconsumeSuccessRate = newMeter("ReconsumeSuccessPerSec", "message", TimeUnit.SECONDS, tags);
        this.reconsumeFailureRate = newMeter("ReconsumeFailurePerSec", "message", TimeUnit.SECONDS, tags);
        this.totalCostOfMessage = newTimer("TotalCostTimeMs", TimeUnit.MILLISECONDS, TimeUnit.SECONDS, tags);
        this.userCostOfMessage = newTimer("UserCostTimeMs", TimeUnit.MILLISECONDS, TimeUnit.SECONDS, tags);
    }

    public String getMetricsId() {
        return metricsId;
    }

    public Meter consumeSuccessRate() {
        return consumeSuccessRate;
    }

    public Meter consumeFailureRate() {
        return consumeFailureRate;
    }

    public Meter reconsumeSuccessRate() {
        return reconsumeSuccessRate;
    }

    public Meter reconsumeFailureRate() {
        return reconsumeFailureRate;
    }

    public Timer totalCostOfMessage() {
        return totalCostOfMessage;
    }

    public Timer userCostOfMessage() {
        return userCostOfMessage;
    }
}
